package com.srcptit.trainning.b2;

public class StringDemo {
	
	/**
	 * Display string "Hello SRC PTIT" from "Hello", "SRC" and "PTIT"
	 */
	public static void concat() {
		// Use \" to print special character.
		String message = "Display string \"Hello SRC PTIT\" from \"Hello\", \"SRC\" and \"PTIT\"";
		System.out.println(message);
		String  str = "Hello";
		// Use + operator
		str += " SRC";
		System.out.println(str);
		// Use concat method
		str = str.concat(" PTIT");	// Should use.
		System.out.println(str);
		System.out.println("-----------------");
	}
	
	/**
	 * Print none alphabet and number from a text
	 */
	public static void printNoneAlphabet() {
		String text = "Hello D12, we are SRC-PTIT 2013 :) ";
		
		String message = "Print none alphabet from text: ".concat("\"").concat(text).concat("\"");
		System.out.println(message);
		
		for(int i = 0; i < text.length(); ++i) {
			// Print none alphabet.
			if(!Character.isAlphabetic(text.charAt(i))) {
				System.out.print(text.charAt(i));
			}
		}
		
		message = "\nPrint number from text: ".concat("\"").concat(text).concat("\"");
		System.out.println(message);
		
		for(int i = 0; i < text.length(); ++i) {
			// Print none alphabet.
			if(Character.isDigit(text.charAt(i))) {
				System.out.print(text.charAt(i));
			}
		}
		System.out.println("\n-----------------");
	}
	
	public static void main(String[] args) {
		printNoneAlphabet();
		concat();
	}
	
}
